'--------------------------------------------------------------------------------
' This file is a "Sample" from the SharePoint Foundation 2010
' Samples
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation.  See these other
' materials for detailed information regarding Microsoft code samples.
' 
' THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'--------------------------------------------------------------------------------

Imports System
Imports System.Runtime.InteropServices
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls

Public Class ConsumerWebPart
    Inherits WebPart

    Dim _provider As IProject = Nothing
    Dim _lbl As Label = Nothing

    Public Sub New()
    End Sub

    Protected Overrides Sub CreateChildControls()
        MyBase.CreateChildControls()

        Try
            _lbl = New Label()

            If _provider IsNot Nothing Then
                If _provider.Id > 0 Then
                    _lbl.Text = _provider.Name & " was selected."
                Else
                    _lbl.Text = "Nothing was selected."
                End If
            Else
                _lbl.Text = "No Provider Web Part Connected."
            End If

            Me.Controls.Add(_lbl)
        Catch ex As Exception
            Me.Controls.Clear()
            Me.Controls.Add(New LiteralControl(ex.Message))
        End Try

    End Sub

    <ConnectionConsumer("Project Name and ID")> _
    Public Sub ThisNameDoesNotMatter(ByVal providerInterface As IProject)
        _provider = providerInterface
    End Sub

End Class
